package com.brooks.demo;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport 可以线程阻塞
 * @Author mihutu
 * @Date 2020/10/20 10:05
 * @Version 1.0
 */
public class DemoTestLockSupport {
    public static void main(String[] args) {
        Thread t = new Thread(()->{
            for (int i=0;i<10;i++){
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(i);
                if(i==5){
                    LockSupport.park();
                }
            }
        });
        t.start();
        //可以先于park执行
        LockSupport.unpark(t);
    }
}
